package servlet;

import dao.UserDao;
import javabean.User;
import javax.servlet.annotation.WebServlet;
import javax.servlet.RequestDispatcher;
import java.io.IOException;
import java.util.List;

@WebServlet("/yanzheng")
public class YanZheng extends javax.servlet.http.HttpServlet {
    private static final long serialVersionUID = 1L;
    public YanZheng() {}
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

        String xm=request.getParameter("xm");
        if(xm==""){
            RequestDispatcher rd=request.getRequestDispatcher("null.jsp");
            rd.forward(request,response);
        }
        String xb=request.getParameter("xb");
        String mm=request.getParameter("mm");
        String tp=request.getParameter("tp");
        User user=new User(xm,xb,mm,tp);

        List<User> list=null;
        UserDao dao=new UserDao();

        try {list = dao.QueryAll();

        } catch (Exception e) {e.printStackTrace();}

        int f=user.pdListUser(list);

        if(f==1){
            RequestDispatcher rd=request.getRequestDispatcher("zhuce_shibai.jsp");
            rd.forward(request,response);
        }else{
            try {
                dao.add(user);
            } catch (Exception e) {e.printStackTrace();}

            RequestDispatcher rd=request.getRequestDispatcher("denglu_chenggong.jsp");
            rd.forward(request,response);
        }
        }
    }

